#include<iostream>
#include<queue>
#include<vector>

using namespace std;
template<class T>
class less1
{
public:
	bool operator()(T& d1, T& d2)
	{
		return d1 < d2;
	}
};
namespace myqueue
{
	template<class T,class compare = less1<T>>
	class priority_queue
	{
	public:
		typedef vector<T> test;
		compare com;
		void push(T d1)
		{
			_data.push_back(d1);
			int children = _data.size() - 1;
			int parent = (children - 1) / 2;
			while (children > 0)
			{
				if (com(_data[children], _data[parent]))
				{
					//swap(parent, children);
					--children;
				}
				if (com(_data[parent], _data[children]))
				{
					swap(_data[parent], _data[children]);
					children = parent;
					parent = (children - 1) / 2;
				}
				else
				{
					break;
				}
			}
		}
		void pop()
		{
	
			swap(_data[0], _data[_data.size() - 1]);
			_data.resize(_data.size() - 1);
			int parent = 0;
			int children = (parent * 2) + 1;
			while (children < (int)_data.size())
			{
				if (com(_data[children], _data[parent]))
				{
					/*int parent = children;
					int children = (parent / 2) + 1;*/
					++children;
					parent = children;
					children = (parent * 2) + 1;
					//continue;
				}
				if (com(_data[parent], _data[children]))
				{
					swap(_data[parent], _data[children]);
					 parent = children;
					 children = (parent * 2) + 1;
				}
			/*	else
				{
					break;
				}*/
			
			}
		}
		T top()
		{
			return _data[0];
		}
	private:
		test _data;
	};
}